const Mock = require('mockjs')

const AttrList=[];
const AttrNames=['客户来源','接洽方式','购车次数','战败原因','意向等级'];
AttrNames.forEach(item=>{
    var obj=Mock.mock({
        id:'@increment',
        name:item,
        state:'@integer(0,1)',
        children:[],
        createtime:'@datetime'
    })
    for(let i=0;i<5;i++){
        obj.children.push(
            Mock.mock({
                id:'@increment',
                name:'@first',
                value:'@integer(0,5)',
                createtime:'@datetime'
            })
        )
    }
    AttrList.push(obj);
})


const SalesTaskList=[];
for(let i=0;i<40;i++){
    SalesTaskList.push(
        Mock.mock({
            id:'@increment',
            guider:'@first',
            reception:'@integer(0,100)',
            intention:'@integer(0,500)',
            fail:'@integer(0,50)',
            order:'@integer(0,100)',
            sales:'@integer(0,200)',
            insurance:'@integer(0,300)',
            boutique:'@integer(0,5000)',
            month:'2021-06',
            createtime:'@datetime',
            nodata:false,
        })
    )
}

const CarpriceList=[];
for(let i=0;i<50;i++){
    CarpriceList.push(Mock.mock({
        id:'@increment',
        'car|1':['宝马','奔驰','玛莎','兰博基尼','五菱','本田','丰田','一汽大众'],
        salesprice:'@float(0, 100, 2, 2)',
        salesprice1:'@float(0, 100, 2, 2)',
        salesprice2:'@float(0, 100, 2, 2)',
        salesprice3:'@float(0, 100, 2, 2)',
        salesprice4:'@float(0, 100, 2, 2)',
        salesprice5:'@float(0, 100, 2, 2)',
        createtime:'@datetime',
        changestate:'@integer(0,1)'
    }))
}

const FeeList=[];
for(let i=0;i<20;i++){
    FeeList.push(Mock.mock({
        id:'@increment',
        'name|1':['上牌费','居住证费','玛莎按揭','兰博基尼按揭','五菱按揭','本田按揭','丰田按揭','一汽大众按揭'],
        fee:'@float(0, 100, 2, 2)',
        createtime:'@datetime',
    }))
}



module.exports = [
    // attrlist
    {
      url: '/api/setting/attrlist',
      type: 'get',
      response: config => {
        
        var mockList=AttrList.filter(o=>true);
        return {
          code: '10000',
          data: {
            total: mockList.length,
            items: mockList
          }
        }
      }
    },
    {
        url: '/api/setting/salestasklist',
        type: 'get',
        response: config => {
          const { month, page = 1, limit = 20, sort } = config.query
            
          let mockList = SalesTaskList.filter(item => {
            if (item.month !== month) return false
            return true
          })
    
          if(mockList.length==0){
            mockList=SalesTaskList.map(obj=>{
                for(var key in obj){
                    if(obj.hasOwnProperty(key) && key!='id' && key!='guider'){
                        obj[key]='';
                    }
                }
                obj.nodata=true;
                obj.month=month;
                return obj;
            })
          }
    
          const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
    
          return {
            code: '10000',
            data: {
              total: mockList.length,
              items: pageList
            }
          }
        }
    },

    // carpricelist
    {
        url: '/api/setting/carpricelist',
        type: 'get',
        response: config => {
          
          var mockList=CarpriceList.filter(o=>true);
          return {
            code: '10000',
            data: {
              total: mockList.length,
              items: mockList
            }
          }
        }
      },
      // carpricelist
    {
        url: '/api/setting/feelist',
        type: 'get',
        response: config => {
          
          var mockList=FeeList.filter(o=>true);
          return {
            code: '10000',
            data: {
              total: mockList.length,
              items: mockList
            }
          }
        }
      },
]